package com.htc.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.htc.dao.ProductMapper;
import com.htc.model.Product;
import com.htc.model.PageResult;
import com.htc.model.request.ProductRequest;

@Service
public class ProductService {
    
	@Autowired
	private ProductMapper productMapper;
	
	public PageResult<Product> queryList(ProductRequest request) {
		Page page = PageHelper.startPage(request.getPage(), request.getLimit());
		List<Product> list =  productMapper.queryList(request.convertWhereStr());
		return new PageResult<Product>(list, page.getTotal(), page.getPageSize(), page.getPageNum());
	}
	
	public void add(Product room) {
		productMapper.insert(room);
	}
	
	public void update(Product room) {
		productMapper.update(room);
	}
	
	public void del(int id) {
		productMapper.del(id);
	}

	public List<Product> findAll() {
		return productMapper.queryList("");
	}
	
	public void updateStorage(int pid,int storage) {
		productMapper.updateStorage(pid,storage);
	}
	
	 public void updateStatus(int status,Integer id){
		 productMapper.updateStatus(status,id);
     }
	
	

}
